home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / CUGUK / PROG_TOO / C013.ZIP / WHAT.C < prev    next >
Text File  |  1990-01-19  |  2KB  |  83 lines

  1. /********************************************************************
  2.  * C Users Group (U.K) C Source Code Library File CUGLIB.013        *
  3.  * Inquiries to: M. Houston, 36 Whetstone Clo. Farquhar Rd.         *
  4.  * Edgbaston, Birmingham B15 2QN ENGLAND                *
  5.  ********************************************************************
  6.  * File name: what.c
  7.  * Program name:what 
  8.  * Source of file: Ron Wellstead
  9.  * Purpose: An MS-DOS copy of the UNIX utility of the same name.
  10.  * Changes: <who what when & why major changes have been made>      
  11.  ********************************************************************/
  12.  
  13. /*
  14.  *
  15.  *    @(#) what.c 1.2 87/07/27 
  16.  *
  17.  *    UNIX style what utility for dos
  18.  *
  19.  *    copyright (c) 1987 Ron Wellsted.
  20.  *    This software is provided on the understanding that it is
  21.  *    NOT to be used for commercial gain. It may be freely distributed
  22.  *    in source or object form among amateur and hobby computer users ONLY!
  23.  *
  24.  *    displays on stdout the what-strings in file(s)
  25.  *    usage:    what files...
  26.  *    written for Microsoft C, link with setargv.obj to expand wildcards
  27.  */
  28. #include    <stdio.h>
  29. #include    <ctype.h>
  30.  
  31. #define    FALSE    0
  32. #define    TRUE    1
  33.  
  34. char what[]="@(#) what VR 1.0.0 15 Jul 1987";
  35.  
  36. main(argc, argv)
  37. int argc;
  38. char **argv;
  39. {
  40.  
  41.     FILE *fp;
  42.  
  43.     if (argc == 1) { /* no args; error */
  44.         fprintf(stderr,"usage: what filespec....\n");
  45.         exit(1);
  46.     } else {
  47.         while (--argc > 0) {
  48.             if ((fp = fopen(*++argv, "rb")) == NULL)
  49.                 fprintf(stderr,"what: Can't open %s\n",*argv);
  50.             else {
  51.                 printf("%s :\n",*argv);
  52.                 filescan(fp);
  53.                 fclose(fp);
  54.             }
  55.         }
  56.     }
  57. }
  58.  
  59. filescan(fp)    /* scan file fp for "@(#)" & output asciz string */
  60. FILE *fp;
  61. {
  62.     int ch,state=0;
  63.  
  64.     while ((ch=getc(fp))!=EOF) {
  65.         if ((state==0)&&(ch=='@'))
  66.             ++state;
  67.         else if ((state==1)&&(ch=='@')) ;
  68.         else if ((state==1)&&(ch=='('))
  69.             ++state;
  70.         else if ((state==2)&&(ch=='#'))
  71.             ++state;
  72.         else if ((state==3)&&(ch==')'))
  73.             ++state;
  74.         else if ((state==4)&&(ch!='\0')&&(ch!='\n'))
  75.             putchar(ch);
  76.         else if (state==4) {
  77.             putchar('\n');
  78.             state=0;
  79.         }
  80.         else state=0;
  81.     }
  82. }
  83.